package com.keda;


import org.apache.http.HttpHost;

import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;


import java.io.IOException;

public class test_update {
    public static void main(String[] args) throws IOException {

        //创建es 客户端
        RestHighLevelClient esClient = new RestHighLevelClient(
                RestClient.builder(new HttpHost("localhost",9200))
        );

        // 修改数据    修改性别为女
        UpdateRequest  request=new UpdateRequest();
            request.index("user").id("1001");
            request.doc(XContentType.JSON,"sex","女");


        UpdateResponse response = esClient.update(request, RequestOptions.DEFAULT);
        System.out.println(response.getResult());


        //关闭es客户端
        try {
            esClient.close();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
